package stream;

import bean.FormData;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: lyy
 * Date: 2021/12/23 15:28
 */
public class QuickStartTest {
	public static void main(String[] args) {
		// List<Student> studentList = Arrays.asList(new Student(19,"哇喔"),
		// 		new Student(2,"歪歪"),
		// 		new Student(13,"你好"),
		// 		new Student(19, "歪歪"),
		// 		new Student(13,"喜欢的"));
		// // 判断list中的对象的某个字段是否有重复值
		// Map<String, List<Student>> listMap = studentList.stream().collect(Collectors.groupingBy(Student::getName));
		// String result = listMap.keySet().stream().filter(key -> listMap.get(key).size() > 1).collect(Collectors.joining(",","姓名[","]不能重复"));
		// System.out.println(result);

		List<FormData> list = list();
		Map<Integer, List<FormData.FormHead>> listMap = list.stream().flatMap(formData -> formData.getFormHeadList().stream())
				.collect(Collectors.groupingBy(FormData.FormHead::getIndex));
		System.out.println(listMap);

	}

	public static List<FormData> list(){
		List<FormData> formDataList = new ArrayList<>();

		FormData formData1 = new FormData();
		List<FormData.FormHead> formHeadList1 = new ArrayList<>();
		FormData.FormHead formHead1_1 = new FormData.FormHead();
		formHead1_1.setIndex(1);
		formHead1_1.setContent("第一例");
		FormData.FormHead formHead1_2 = new FormData.FormHead();
		formHead1_2.setIndex(2);
		formHead1_2.setContent("哈哈");
		FormData.FormHead formHead1_3 = new FormData.FormHead();
		formHead1_3.setIndex(3);
		formHead1_3.setContent("哈哈1");
		formHeadList1.add(formHead1_1);
		formHeadList1.add(formHead1_2);
		formHeadList1.add(formHead1_3);
		formData1.setFormDataId(1);
		formData1.setFormHeadList(formHeadList1);
		formDataList.add(formData1);

		FormData formData2 = new FormData();
		List<FormData.FormHead> formHeadList2 = new ArrayList<>();
		FormData.FormHead formHead2_1 = new FormData.FormHead();
		formHead2_1.setIndex(1);
		formHead2_1.setContent("嗯嗯");
		FormData.FormHead formHead2_2 = new FormData.FormHead();
		formHead2_2.setIndex(2);
		formHead2_2.setContent("哈哈");
		FormData.FormHead formHead2_3 = new FormData.FormHead();
		formHead2_3.setIndex(3);
		formHead2_3.setContent("哈哈1");
		formHeadList2.add(formHead2_1);
		formHeadList2.add(formHead2_2);
		formHeadList2.add(formHead2_3);
		formData2.setFormDataId(2);
		formData2.setFormHeadList(formHeadList2);
		formDataList.add(formData2);

		FormData formData3 = new FormData();
		List<FormData.FormHead> formHeadList3 = new ArrayList<>();
		FormData.FormHead formHead3_1 = new FormData.FormHead();
		formHead3_1.setIndex(1);
		formHead3_1.setContent("嗯嗯");
		FormData.FormHead formHead3_2 = new FormData.FormHead();
		formHead3_2.setIndex(2);
		formHead3_2.setContent("哈哈");
		FormData.FormHead formHead3_3 = new FormData.FormHead();
		formHead3_3.setIndex(3);
		formHead3_3.setContent("哈哈1");
		formHeadList3.add(formHead3_1);
		formHeadList3.add(formHead3_2);
		formHeadList3.add(formHead3_3);
		formData3.setFormDataId(3);
		formData3.setFormHeadList(formHeadList3);
		formDataList.add(formData3);
		return formDataList;
	}
}
